/*
 * TwoButton.cpp
 *
 *  Created on: 10/ago/2011
 *      Author: marcolembo
 */

#include "TwoButton.h"
#ifndef _WP_
#define _WP_
#include "WProgram.h"
#endif


const TwoButton::BtnRange TwoButton::rangeEnterBtn  = {100, 200};

const TwoButton::BtnRange TwoButton::rangeEscBtn  = {500, 600};




TwoButton::TwoButton(short _pin)
: m_pin(_pin),
  m_wasPressedBtnOne(false),
  m_wasPressedBtnTwo(false)
{

}

bool TwoButton::IsBtnOnePressed() const
{
	bool res = false;
	short value = analogRead(m_pin);
	bool IsPressedNow = (value > rangeEnterBtn.start  &&  value < rangeEnterBtn.end);
	if(IsPressedNow)
	{
		if(!m_wasPressedBtnOne)
		{
			res = true;
			m_wasPressedBtnOne = IsPressedNow;
		}
	}
	else
		m_wasPressedBtnOne = false;
	return res;
}
bool TwoButton::IsBtnTwoPressed() const
{
	bool res = false;
	short value = analogRead(m_pin);
	bool IsPressedNow = (value > rangeEscBtn.start  &&  value < rangeEscBtn.end);
	if(IsPressedNow)
	{
		if(!m_wasPressedBtnTwo)
		{
			res = true;
			m_wasPressedBtnTwo = IsPressedNow;
		}
	}
	else
	    m_wasPressedBtnTwo = false;
	return res;
}

TwoButton::~TwoButton() {
	// TODO Auto-generated destructor stub
}
